package com.dragon.gencode.project.controller;

import com.dragon.gencode.conf.db.DynamicDataSourceContextHolder;
import com.dragon.gencode.conf.db.TargetDataSource;
import com.dragon.gencode.project.domain.AjaxResult;
import com.dragon.gencode.project.domain.GenTable;
import com.dragon.gencode.project.domain.GenTableColumn;
import com.dragon.gencode.project.server.GenServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @ClassName GenController
 * @Description TODO
 * @Author dragon
 * @Date 2020-06-18 15:55
 * @Version 1.0
 **/
@Controller
@RequestMapping("gen")
public class GenController {

    @Autowired
    GenServer genServer;

    @ResponseBody
    @GetMapping("/getTables")
//    @TargetDataSource(DynamicDataSourceContextHolder.DataSourceKey.GEN) // 默认
    public AjaxResult getTables() {
        List<GenTable> tables = genServer.getTables();
        return AjaxResult.success(tables);
    }

    @ResponseBody
    @GetMapping("/getColumns")
    public AjaxResult getColumns(String tableName) {
        List<GenTableColumn> columns = genServer.getColumns(tableName);
        return AjaxResult.success(columns);
    }
}
